<?php
namespace app\view\controller;

use app\api\controller\BaseController;
use app\common\exception\SuccessException;
use app\facade\view\CategoryService;
use think\facade\Request;
use think\Db;

/**
 * 首页
 */
class Category extends BaseController
{
    /** 获取主类 */
    public function categoryList(){
        $params = Request::param();
        $where = [
            'category_status' =>  1,
            'type' =>  $params['type'],
        ];
        $fields = 'category_id, category_name';
        $res = CategoryService::getAll($where, $fields, ['order' => 'dec']);
        throw new SuccessException(['content' => $res, 'msg' => 'SUCCESS']);
    }

    /** 获取子类 */
    public function category(){
        $params = Request::param();
        $where = [
            'category_status' =>  1,
            'parent_id' =>  $params['id'],
        ];
        $fields = 'category_id, category_name';
        $res = CategoryService::getAll($where, $fields, ['order' => 'dec']);
        throw new SuccessException(['content' => $res, 'msg' => 'SUCCESS']);
    }
}
